package com.sxyjhh.utils.util;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

import java.text.SimpleDateFormat;
import java.util.Date;

public class JsonDateValueProcessor implements JsonValueProcessor {
	private SimpleDateFormat simpleDateformat = null;
	public JsonDateValueProcessor(SimpleDateFormat simpDateformat){
		this.simpleDateformat = simpDateformat;
    }
	@Override
    public Object processArrayValue(Object value,JsonConfig config){
		return process(value);
    }
	@Override
    public Object processObjectValue(String key, Object value, JsonConfig config) {
        return process(value);
    }
	
	private Object process(Object value){  
        if(value instanceof Date){
        	return simpleDateformat.format(value);  
        }
        return (null == value) ? "" : value.toString();
    }
}
